% Demonstrate how to make and work with dotsDrawableTexture objects.
clear
clear classes
clc

% access the manager that deals with drawing
dm = dotsTheDrawablesManager.theObject;

% create a texture-drawing object
tx = dm.newObject('dotsDrawableTextures');

% configure the texture object to draw a checkerboard texture with some
% colored checkers.
% The "checkerTextureMaker" function is included along with this
% demo script.  It knows how to make a checkerboard texture with
% Psychtoolbox.  It expectes to receive the texture object and a color
% parameter.
red = [255 0 0];
tx.textureMakerFevalable = {@checkerTextureMaker, red};

% create a target dot to display near or behind the texture
dot = dm.newObject('dotsDrawableTargets');
blue = [0 0 255];
dot.dotSize = 10;
dot.color = blue;

% add the texture and dot objects to a group to draw them together
%   the last parameter allows us to sort the group by drawing order
dm.addObjectToGroup(dot, 'demo group', 1);
dm.addObjectToGroup(tx, 'demo group', 2);
dm.activateGroup('demo group');

% get ready to draw in a Psychtoolbox Screen window
dm.openScreenWindow;

% draw the checkered texture at a small size
%   it will occlude the blue dot
tx.width = 1;
tx.height = 1;
dm.mayDrawNextFrame;
pause(1);

% draw the checkered texture at a larger size
%   it will still occlude the blue dot
tx.width = 10;
tx.height = 5;
dm.mayDrawNextFrame;
pause(1);

% draw the checkered texture at a larger size, and other changes
%   It will rotate and move to reveal the blue dot behind it!
tx.x = -5;
tx.rotation = 45;
tx.opacity = .5;
tx.falseColor = [64 32 128];
dm.mayDrawNextFrame;
pause(1);

% close the Psychtoolbox Screen window
dm.closeScreenWindow;